package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.service.IVoucherOrderService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author 朱振国
 * @since 2022-12-22
 */
@RestController
@RequestMapping("/voucher-order")
public class VoucherOrderController {

    @Resource(name = "voucherOrderClusterRedisMQServiceImpl")
    private IVoucherOrderService voucherOrderService;

    /**
     * 优惠券秒杀
     * 需要做下单，在tb_voucher_order表中创建订单
     * 扣库存的操作，tb_seckill_voucher中扣减库存
     * tips:
     *  1.秒杀是否开始或者结束
     *  2.库存是否充足，不足则无法下单
     * @param voucherId 优惠券id
     * @return {@link Result}
     */
    @PostMapping("/seckill/{id}")
    public Result seckillVoucher(@PathVariable("id") Long voucherId) {
        return voucherOrderService.seckillVoucher(voucherId);
    }
}
